/**
 * Created with IntelliJ IEDA.
 * Description:
 * User:86186
 * Date:2023-04-21
 * Time:22:58
 */

/**
 * JZ14 剪绳子
 */

public class cutRope {
    public static void main(String[] args) {
        System.out.println(cutRope(8));
    }
    public static int cutRope(int n) {
        if (n < 2) {
            return 0;
        }
        if (n == 2) {
            return 1;
        }
        if (n == 3) {
            return 2;
        }
        // dp[i] 表示长度为 i 的绳子剪成若干段后的最大乘积
        int[] dp = new int[n + 1];
        // 边界条件
        dp[1] = 1;
        dp[2] = 2;
        dp[3] = 3;
        for (int i = 4; i <= n; i++) {
            for (int j = 1; j <= i / 2; j++) {
                dp[i] = Math.max(dp[i], dp[j] * dp[i - j]);
            }
        }
        return dp[n];
    }

}
